package com.winit.bean.web;

import com.alibaba.fastjson.JSONObject;
import com.winit.bean.model.Bean;
import com.winit.bean.service.BeanService;
import com.winit.common.base.bean.ExecuteResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by wanglin on 2018/6/4.
 */
@Component
@Api(value = "bean", tags = {"bean"}, description = "bean")
@RestController
@RequestMapping("/api/v1/bean")
public class BeanController {
    @Autowired
    BeanService beanService;

    @RequestMapping(value = "/findByPathAndName", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "根据名称与地址查询bean")
    @ResponseBody
    public ExecuteResult<Bean> findByPathAndName(@ApiParam(value = "根据地址查询") @RequestParam(value = "path", required = false) String path,
                                       @ApiParam(value = "根据名称查询") @RequestParam(value = "name", required = false) String name
    ) {
        ExecuteResult executeResult=new ExecuteResult();
        Bean er = beanService.findByPathAndName(path, name);
        executeResult.setData(er);
        return executeResult;
    }



    @RequestMapping(value = "/batchSaveBean", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "保存bean")
    @ResponseBody
    public ExecuteResult batchSaveBean(@RequestBody JSONObject jsonObject){
        ExecuteResult executeResult = new ExecuteResult();
        beanService.batchSaveBean(jsonObject);
        return executeResult;
    }


//    @RequestMapping(value = "/getParam", method = RequestMethod.GET)
//    @ResponseStatus(HttpStatus.OK)
//    @ApiOperation(value = "获取参数信息")
//    @ResponseBody
//    public ExecuteResult<Bean> getParam(@ApiParam(value = "方法参数ID") @RequestParam(value = "paramConfigId", required = false) String paramConfigId
//    ) {
//        ExecuteResult executeResult=new ExecuteResult();
//        executeResult.setData(beanService.getParam(paramConfigId));
//        return executeResult;
//    }





}
